package com.jwsoft.manager.core.gateway.controller;

import com.bifang.assistant.common.constants.Validators;
import com.bifang.engine.assistant.core.domain.AppResponse;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.protect.core.annotation.Idempotent;
import com.bifang.engine.protect.core.annotation.NoSignCrypto;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.vo.eduHouse.EduHouseVO;
import com.jwsoft.manager.common.vo.eduHouse.StudentHouseQueryVO;
import com.jwsoft.manager.common.vo.eduStudentHouse.EduStudentHouseKeyVO;
import com.jwsoft.manager.common.vo.eduStudentHouse.EduStudentHouseQueryByRealpVO;
import com.jwsoft.manager.common.vo.eduStudentHouse.EduStudentHouseQueryVO;
import com.jwsoft.manager.common.vo.eduStudentHouse.EduStudentHouseVO;
import com.jwsoft.manager.core.integration.EduStudentHouseIntegration;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 录取学生房产信息表网关
 *
 * @author wangtao
 * @since 2022-12-01
 */
@RestController
@RequestMapping(value = "/doc/api")
@Tag(name = "录取学生房产信息表", description = "录取学生房产信息表")
public class EduStudentHouseController {

    @Autowired
    public EduStudentHouseIntegration eduStudentHouseIntegration;

    @Operation(summary = "录取学生房产信息表分页查询",description = "录取学生房产信息表分页查询")
    @PostMapping(value = "/eduStudentHouse0001", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduStudentHouseVO>> getList(@RequestBody @Validated EduStudentHouseQueryVO vo) {
        return AppResponse.successData(eduStudentHouseIntegration.getList(vo));
    }

    @Operation(summary = "录取学生房产信息表根据主键查询详情",description = "录取学生房产信息表根据主键查询详情")
    @PostMapping(value = "/eduStudentHouse0002", produces = "application/json;charset=UTF-8")
    public AppResponse<EduStudentHouseVO> getById(@RequestBody @Validated EduStudentHouseKeyVO vo) {
        return AppResponse.successData(eduStudentHouseIntegration.getById(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "录取学生房产信息表新增",description = "录取学生房产信息表新增")
    @PostMapping(value = "/eduStudentHouse0004", produces = "application/json;charset=UTF-8")
    public AppResponse<EduStudentHouseVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduStudentHouseVO vo) {
        return AppResponse.successData(eduStudentHouseIntegration.add(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "录取学生房产信息表修改",description = "录取学生房产信息表修改")
    @PostMapping(value = "/eduStudentHouse0005", produces = "application/json;charset=UTF-8")
    public AppResponse<EduStudentHouseVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduStudentHouseVO vo) {
        return AppResponse.successData(eduStudentHouseIntegration.edit(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "录取学生房产信息表删除",description = "录取学生房产信息表删除")
    @PostMapping(value = "/eduStudentHouse0006", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduStudentHouseKeyVO vo) {
        eduStudentHouseIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }

    @Operation(summary = "学生房产使用情况查询",description = "学生房产使用情况查询")
    @PostMapping(value = "/eduStudentHouse0007", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduStudentHouseVO>> queryStudentHouseInfo(@RequestBody @Validated StudentHouseQueryVO vo) {
        return AppResponse.successData(eduStudentHouseIntegration.queryStudentHouseInfo(vo));
    }

    @Operation(summary = "家长端学生房产使用情况查询(通过房产证号)",description = "家长端学生房产使用情况查询(通过房产证号)")
    @PostMapping(value = "/eduStudentHouse0008", produces = "application/json;charset=UTF-8")
    public AppResponse<EduHouseVO> getListByRealp(@RequestBody @Validated EduStudentHouseQueryByRealpVO vo) {
        return AppResponse.successData( eduStudentHouseIntegration.getListByRealp(vo));
    }
    @Operation(summary = "家长端我的房产使用情况查询",description = "家长端我的房产使用情况查询")
    @PostMapping(value = "/eduStudentHouse0009", produces = "application/json;charset=UTF-8")
    public AppResponse<List<EduHouseVO>> getMyUserHouse(@RequestBody @Validated EduStudentHouseQueryByRealpVO vo) {
        return AppResponse.successData( eduStudentHouseIntegration.getMyUserHouse(vo));
    }
    @Operation(summary = "房产使用控制缓存清除",description = "房产使用控制缓存清除")
    @PostMapping(value = "/useHouseCache0002", produces = "application/json;charset=UTF-8")
    public AppResponse clearCache(@RequestBody @Validated EduStudentHouseQueryByRealpVO vo) {
        eduStudentHouseIntegration.clearCache(vo);
        return AppResponse.successMsg("清除成功");
    }

    @RequestMapping(
            value = "/eduStudentHouse0010",
            method = {RequestMethod.POST, RequestMethod.GET})
    @Operation(summary = "学生房产使用情况导出", description = "学生房产使用情况导出")
    @NoSignCrypto
    public void downloadData(
            HttpServletRequest request,
            @RequestParam Map<String, Object> paramMap,
            @RequestBody(required = false) StudentHouseQueryVO vo,
            HttpServletResponse response) {

        if (StringUtils.isBlank(vo.getModelCode())) {
            throw new AppException("excel模板编号不能为空");
        }
        eduStudentHouseIntegration.downloadData(vo,response);

    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "修改学生房产信息状态",description = "修改学生房产信息状态")
    @PostMapping(value = "/eduStudentHouse0011", produces = "application/json;charset=UTF-8")
    public AppResponse<EduStudentHouseVO> updateStatus(@RequestBody @Validated EduStudentHouseVO vo) {
        return AppResponse.successData(eduStudentHouseIntegration.updateStatus(vo));
    }



}
